package com.kltong.inf.dubbo.config;

import org.springframework.beans.factory.InitializingBean;

import com.alibaba.csp.sentinel.log.LogBase;
import com.alibaba.csp.sentinel.transport.config.TransportConfig;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

@Setter
@Slf4j
public class SentinelConfig implements InitializingBean {

	private SentinelProperties sentinelProperties;
	private static final String SENTINEL_PROJECT_NAME = "project.name";

	@Override
	public void afterPropertiesSet() throws Exception {

		log.info("初始化sentinel配置");
		/**
		 * init sentinel config
		 */
		System.setProperty(LogBase.LOG_DIR, sentinelProperties.getLogDir());
		System.setProperty(TransportConfig.CONSOLE_SERVER, sentinelProperties.getDashBoardServer());
		System.setProperty(TransportConfig.SERVER_PORT, sentinelProperties.getApiPort());
		System.setProperty(SENTINEL_PROJECT_NAME, sentinelProperties.getAppName());

		log.info("初始化sentinel配置完成, system properties: {}", System.getProperties());
	}

}
